/**
 * 
 */
package com.zxc.redis.RBucket;

import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import com.zxc.redis.AnyObject;

/**
 * 分布式Object
 * @author Administrator
 *
 */
public class RBucketDemo {

	public static void main(String[] args) {
		Config config = new Config();
		config
			//.setCodec(new FstCodec())
			.useSingleServer() //单例模式
			.setAddress("192.168.1.122:6379")//连接地址
			.setDatabase(1) // 数据库索引位置
			.setPassword("shijie99test") // 密码
			.setClientName("channelbatch") // 客户端名称
			;
		RedissonClient redisson = Redisson.create(config);
		RBucket<AnyObject> bucket = redisson.getBucket("anyObject1");
		
		bucket.set(new AnyObject(1));
		
		AnyObject obj = bucket.get();
		System.out.println("获取对象信息："+obj.toString());
		
		bucket.trySet(new AnyObject(3));
		
		obj = bucket.get();
		System.out.println("trySet后，获取对象信息："+obj.toString());
		
		bucket.compareAndSet(new AnyObject(4), new AnyObject(5));
		
		obj = bucket.get();
		System.out.println("compareAndSet后，获取对象信息："+obj.toString());
		
		obj = bucket.getAndSet(new AnyObject(6));
		
		System.out.println("getAndSet后，获取对象信息（old）："+obj.toString());
		
		obj = bucket.get();
		System.out.println("getAndSet后，获取对象信息(new)："+obj.toString());
	}
}
